<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>点击改变盒子的大小</title>
  <style>
    div {
      width: 150px;
      height: 150px;
      background-color: pink;
    }
  </style>
</head>
<body>
  <button onclick="fn()">点击改变盒子的大小</button>
  <div></div>
  <script>
    var div = document.querySelector('div'), i = 1;
    function fn() {
      i++
      if (i % 2 == 0) {
        div.style.width = 50 + 'px'
        div.style.height = 50 + 'px'
      } else {
        div.style.width = 150 + 'px'
        div.style.height = 150 + 'px'
      }
    }
  </script>
</body>
</html>